package com.androidian.tippit.fragments;

import com.androidian.tippit.ActivityHome;
import com.androidian.tippit.R;
import com.androidian.tippit.utilities.Fonts;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.SlidingMenu.OnCloseListener;
import com.slidingmenu.lib.SlidingMenu.OnOpenListener;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;



public class FragmentMenu extends Fragment 
{

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
	{
		
		final View view = inflater.inflate(R.layout.fragment_menu,
				container, false);		
		
		/** Check for an id only specified in layout-large-land */
			if(getActivity().findViewById(R.id.landscape_indicator) != null)
			{
				
				showAllButtons(view);
	
			}
			
		
		Fonts.setRobotoFont(this.getActivity(), view);

		ActivityHome mActivity = (ActivityHome) getActivity();
		
		SlidingMenu mSlidingMenu = mActivity.mSlidingMenu;

		
		mSlidingMenu.setOnCloseListener(new OnCloseListener()
		{

			@Override
			public void onClose() 
			{
				
				hideAllButtons(view);
				
			}

		});

		mSlidingMenu.setOnOpenListener(new OnOpenListener()
		{

			@Override
			public void onOpen() 
			{
				
				showAllButtons(view);
				
			}
							
		});
		
		return view;
		
	}
	
	

	
	
	private void hideAllButtons(View view)
	{
		
		int count = ((ViewGroup)view).getChildCount();

		for(int i = 0; i < count; i++)
		{
			 
			View mChildView = ((ViewGroup)view).getChildAt(i);
		        
		    if(mChildView instanceof Button)
		    {

		    	Button mButton = (Button) mChildView;
	        	
		        mButton.setVisibility(View.INVISIBLE);
		        	
		    }
		    
		 }

	}
	
	private void showAllButtons(View view)
	{
		
		int count = ((ViewGroup)view).getChildCount();

		for(int i = 0; i < count; i++)
		{
			 
			View mChildView = ((ViewGroup)view).getChildAt(i);
		        
		    if(mChildView instanceof Button)
		    {

		    	Button mButton = (Button) mChildView;
	        	
	        	mButton.setVisibility(View.VISIBLE);
	        	
	        	Animation anilmation = AnimationUtils.loadAnimation(getActivity(),
	  			      R.anim.card_animation);
	        	
	        	anilmation.setStartOffset(i * 75);
	        	
	        	mButton.startAnimation(anilmation);			
	        	
		    }
		    
		 }

	}

	
}
